package com.project.nimsen.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.project.nimsen.dao.IBaseDao;
import com.project.nimsen.dto.ColfileDto;
import com.project.nimsen.service.IColfileService;
import com.project.nimsen.service.IColtypeService;
import com.project.jdbc.dao.IBaseJdbcDao;
import com.project.jdbc.service.BaseServiceImpl;
import com.project.jdbc.utils.Finder;
@Repository("colfileService")
public class ColfileServiceImpl extends BaseServiceImpl implements
		IColfileService {
	@Resource
	IBaseDao baseDao;
	@Resource
	IColtypeService coltypeService;
	protected IBaseJdbcDao getBaseDao() {
		return baseDao;
	}
	public List<Map<String, Object>> findFileInfoByDto(ColfileDto dto)
			throws Exception {
		Finder finder = new Finder("select fil.id,fil.filename,fil.srcname,fil.autoname,"
			+ "fil.filetype,fil.createTime from fileinfo as fil left join colfile as "
			+ "colf on fil.id = colf.fileid left join filearchivrelation as fcr on "
			+ "colf.relationid=fcr.id where fil.active!=1 and colf.active!=1 and "
			+ "fcr.active!=1");
		if(StringUtils.isNotBlank(dto.getColtypeid())){
			finder.append(" and colf.coltypeid=:coltypeid");
			finder.setParam("coltypeid", dto.getColtypeid());
		}
		if(StringUtils.isNotBlank(dto.getRelatiovalue())){
			finder.append(" and fcr.relationvalue=:relatiovalue");
			finder.setParam("relatiovalue", dto.getRelatiovalue());
		}
		return baseDao.queryForList(finder);
	}
	public List<Map<String, Object>> findTagFileByDto(ColfileDto dto)
			throws Exception {
		Finder finder = new Finder("select fil.id,fil.filename,fil.srcname,fil.autoname,"
			+ "fil.filetype,fil.createTime from fileinfo as fil left join colfile as "
			+ "colf on fil.id = colf.fileid left join filearchivrelation as fcr on "
			+ "colf.relationid=fcr.id where fil.active!=1 and colf.active!=1 and "
			+ "fcr.active!=1");
		if(StringUtils.isNotBlank(dto.getColtypeid())){
			finder.append(" and colf.coltypeid=:coltypeid");
			finder.setParam("coltypeid", dto.getColtypeid());
		}
		if(StringUtils.isNotBlank(dto.getRelatiovalue())){
			finder.append(" and fcr.relationvalue=:relatiovalue");
			finder.setParam("relatiovalue", dto.getRelatiovalue());
		}
		return baseDao.queryForList(finder);
	}

}
